#include <bits/stdc++.h>
using namespace std;

using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;

const int N=1e6+5;

void Solve(){
   
   return;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<vector<int>> v(n+1,vector<int>(n+1,0));
        vector<int> vn(2*n+1,0);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                cin>>v[i][j];
            }
        }
        ll sum=0;
        for(int i=1;i<2*n+1;i++){
            sum+=i;
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                vn[i+j]=v[i][j];
            }
        }
        for(int i=1;i<2*n+1;i++){
            sum-=vn[i];
        }
        vn[1]=sum;
        for(int i=1;i<2*n+1;i++){
            if(i>1)cout<<" ";
            cout<<vn[i];
        }
        cout<<endl;
    }
    

   return 0;
}